#!/usr/bin/python3.5
# -*- coding utf-8
import scrapy
from douban_book.DouBanBookItem import DouBanBookItem


class DouBanSpider(scrapy.Spider):
    name = "douban_name"
    start_urls = ['https://book.douban.com/top250']
    allowed_domains = ['douban.com']

    '''
    作者、书名、编辑年月、价格、出版社、分数
    
    '''

    def parse(self, response):
        for item in response.xpath('//tr[@class="item"]'):
            book = DouBanBookItem()
            book['book_name'] = item.xpath('td[2]/div[1]/a/@title').get()
            content = item.xpath('td[2]/p[1]/text()').get()
            book['publisher'] = content
            book['rating'] = item.xpath('td[2]/div[2]/span[2]/text()').get()
            yield book
